package com.Q.items;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.Q.podcastq.R;



public class ItemListBaseAdapter extends BaseAdapter {
	private static ArrayList<item> itemDetailsrrayList;


	private LayoutInflater l_Inflater;

	public ItemListBaseAdapter(Context context, ArrayList<item> results) {
		itemDetailsrrayList = results;
		l_Inflater = LayoutInflater.from(context);
	}

	public int getCount() {
		return itemDetailsrrayList.size();
	}

	public Object getItem(int position) {
		return itemDetailsrrayList.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		ImageButton boton = null;
		if (convertView == null) {
			convertView = l_Inflater.inflate(R.layout.item_list, null);
			holder = new ViewHolder();
			holder.txt_itemName = (TextView) convertView.findViewById(R.id.nombre);
			holder.txt_itempais = (TextView) convertView.findViewById(R.id.pais);
			holder.txt_itemcargo = (TextView) convertView.findViewById(R.id.cargo);
			holder.itemImage = (ImageView) convertView.findViewById(R.id.list_image);
			holder.boton = (ImageButton) convertView.findViewById(R.id.descargarboton);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.txt_itemName.setText(itemDetailsrrayList.get(position).getName());
		holder.txt_itempais.setText(itemDetailsrrayList.get(position).getItemDescription());
		holder.txt_itemcargo.setText(itemDetailsrrayList.get(position).getPrice());
		holder.itemImage.setImageBitmap(itemDetailsrrayList.get(position).getImageNumber());
		if("1".equalsIgnoreCase(itemDetailsrrayList.get(position).getDescargado()))
			holder.boton.setImageBitmap(null);
		else
			holder.boton.setImageResource(R.drawable.attchment);
			holder.boton.setOnClickListener(itemDetailsrrayList.get(position).listener);
			holder.boton.setFocusable(false);
		return convertView;
	}



	static class ViewHolder {
		TextView txt_itemName;
		TextView txt_itempais;
		TextView txt_itemcargo;
		ImageView itemImage;
		ImageButton boton;
	}
}
